<template>
	<div class="topicAuditList w944">
		<alert ref="alert"></alert>
		<deleteAlert ref="deleteAlert"></deleteAlert>
		<div class="label_top">
			<p>话题管理</p>
		</div>
		<div class="label_table">
			<div class="el-tabs-report">
				<a class="listTwo advise" @click="topicList" style="margin-left: 0;">话题列表</a>
				<a class="listOne" style="margin-left: 20px">话题审核</a>
				<a class="listTwo" @click="importDaoChu">导出数据</a>
				<div class="msearch">
					<input placeholder="请输入话题、学员名字……" v-model="search"/>
					<a @click="getPageSearch"><img src="../../assets/qudaoImg/search.png"/></a>
				</div>
			</div>
			<el-table ref="multipleTable" :data="tableData" border @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="60"></el-table-column>
				<el-table-column prop="title" label="话题"></el-table-column>
				<el-table-column label="创建者" width="100">
					<template slot-scope="scope">
						<span><img src="../../assets/qudaoImg/anonymous.png" v-if="scope.row.cryptonym==1">{{scope.row.nickname}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="dtHtTypeAlias" label="话题类型"></el-table-column>
				<el-table-column label="话题详情">
					<template slot-scope="scope">
						<el-button @click="handleSeen(scope.row)">查看</el-button>
					</template>
				</el-table-column>
				<el-table-column prop="createTime" label="发布时间" width="150"></el-table-column>
				<el-table-column label="审核状态" width="150">
					<template slot-scope="scope">
						<span v-if="scope.row.auditState==0" style="color: #44CEF6">待审核</span>
						<span v-if="scope.row.auditState==2">已拒绝</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="130">
					<template slot-scope="scope">
						<div v-if="scope.row.auditState==0">
							<el-button @click="handlePass(scope.row)">通过</el-button>
							<el-button @click="handleRefuse(scope.row)" class="blue">拒绝</el-button>
							<el-button @click="handleDelete(scope.row)" class="red">删除</el-button>
						</div>
						<div v-if="scope.row.auditState==2">
							<el-button @click="handlePass(scope.row)">通过</el-button>
							<el-button @click="handleDelete(scope.row)" class="red">删除</el-button>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<div class="fenyeMargin">
				<el-button @click="toggleSelection(tableData)" class="allSelect">全选</el-button>
				<el-button @click="handleDeleteAll" class="allDelete">批量删除</el-button>
				<div class="pag_block">
					<el-pagination @current-change="handleCurrentChange" :current-page="currentpage" :page-size="pagesize" layout="prev, pager, next" :total="total"></el-pagination>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import alert from '../../components/Alert.vue';
	import deleteAlert from '../../components/deleteAlert.vue';
	export default {
		data() {
			return {
				topicAuditList:'',
				search:'',
				tableData:[],
				multipleSelection: [],
		        pagesize: 15,
		        currentpage: 1,
		        total: 1,
		        deleteType:'delete'
			}
		},
		methods: {
			getTableList(){
				this.$ajax({
					url: this.$root.jifuUrl + "/mns/qzDtHt/selectQzHtAuditList",
					headers:{'ContentType': 'application/json; charset=utf-8'},
					method: 'POST',
					data: {
						page:this.currentpage,
						num:this.pagesize,
						fuzzyFields:this.search,
						rootcompanyid:1
					},
					success: res => {
						if(res.data.code == 200) {
							this.tableData = res.data.data.list;
							this.total=res.data.data.pageParam.items;
						}
					}
				});
			},
			handlePass(row){
				let arr = [];
				arr.push(row.id);
				this.$ajax({ 
					url: this.$root.jifuUrl + "/mns/qzDtHt/updateQzDtHtAuditState",
					headers:{'ContentType': 'application/json; charset=utf-8'},
					method: 'POST',
					data:{ids:arr,auditState:1},
					success: res => {
						if(res.data.code == 200) {
							this.$rootFunction().deleteResSuccess();
						}else{
							this.failText = res.data.message;
							this.$rootFunction().deleteResFail();
						}
					}
				});
			},
			handleRefuse(row){
				let arr = [];
				arr.push(row.id);
				this.$ajax({ 
					url: this.$root.jifuUrl + "/mns/qzDtHt/updateQzDtHtAuditState",
					headers:{'ContentType': 'application/json; charset=utf-8'},
					method: 'POST',
					data:{ids:arr,auditState:2},
					success: res => {
						if(res.data.code == 200) {
							this.$rootFunction().deleteResSuccess();
						}else{
							this.failText = res.data.message;
							this.$rootFunction().deleteResFail();
						}
					}
				});
			},
			handleDelete(row){
				this.transitionRow = row;
				this.$rootFunction().rootDelete();
			},
			handleDeleteAll() {
				this.$rootFunction().rootDeleteAll();
			},
			deleteSubmit() {
				if(this.deleteType == 'delete'){
					let arr = [];
					arr.push(this.transitionRow.id);
					let s = arr;
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/qzDtHt/deleteQzDtList",
						headers:{'ContentType': 'application/json; charset=utf-8'},
						method: 'POST',
						data:s,
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}else{ 
					let s=this.multipleSelection;
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/qzDtHt/deleteQzDtList",
						headers:{'ContentType': 'application/json; charset=utf-8'},
						method: 'POST',
						data:s,
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}
			},
			handleSeen(row){
				this.$router.push({
					name:'topicContent',
					params: {
						countId:row.id
					}
				})
			},
			topicList(){
				this.$router.push({
					name:'topicManager'
				})
			},
			toggleSelection(rows) {
				if(rows) {
					rows.forEach(row => {
						this.$refs.multipleTable.toggleRowSelection(row, !this.allSelect)
					})
					this.allSelect = !this.allSelect;
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = [];
				val.forEach(row => {
					this.multipleSelection.push(row.id);
				})
			},
			handleCurrentChange(value) {
				this.currentpage = value;
				this.getTableList();
			},
			getPageSearch(){
				this.currentpage=1;
				this.getTableList();
			},
			importDaoChu(){
				
			}
		},
		components: {
			alert,
			deleteAlert
		},
		mounted: function() {
			this.getTableList();
			this.topicAuditList = this.$root.huasan.topicAuditList;
		}
	}
</script>

<style>
	.topicAuditList .advise{border: 1px solid #44CEF6;box-sizing: border-box;margin-left: 20px;position: relative;top: 1px;}
</style>